package comparable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class MyComparable implements Comparable<MyComparable> {

	int i;
	
	public MyComparable(int i) {
		this.i = i;
	}
	
	@Override
	public int compareTo(MyComparable o) {
		return this.i - o.i;
	}
	
	@Override
	public String toString() {
		return Integer.toString(i);
	}
	
	public static void main(String[] args) {
		MyComparable c1, c2, c3;
		c1 = new MyComparable(10);
		c2 = new MyComparable(5);
		c3 = new MyComparable(15);
		List<MyComparable> list = new ArrayList<MyComparable>();
		list.add(c1);
		list.add(c2);
		list.add(c3);
		
		Collections.sort(list);
		System.out.println(list);
		
		list.clear();
		list.add(c1);
		list.add(c2);
		list.add(c3);
		
		Collections.sort(list, new Comparator<MyComparable>() {
			@Override
			public int compare(MyComparable o1, MyComparable o2) {
				return o1.i - o2.i;
			}
		});
		System.out.println(list);
	}
	
}
